package com.bjc.core.bean.request;

import java.time.LocalDateTime;

import org.apache.commons.lang3.StringUtils;
import org.springframework.mail.SimpleMailMessage;

import com.bjc.base.bean.request.BaseReqVO;
import com.bjc.base.core.ConfigEnvironment;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;


/**
 * 邮件发送记录
 * 
 * @author 许自辉
 * @date 2017年9月1日
 */
@Getter 
@Setter 
@ToString
@ApiModel("维度请求")
public class EmailRecordReqVO extends BaseReqVO {

	@ApiModelProperty(value = "应用名", hidden = true)
	private String appName;

	@ApiModelProperty("发送人邮件地址")
	private String fromAddress;

	@ApiModelProperty("指定回复人邮件地址")
	private String replyToAddress;

	@ApiModelProperty("收件人邮件地址")
	private String toAddress;

	@ApiModelProperty("抄送人邮件地址")
	private String ccAddress;

	@ApiModelProperty("秘密 抄送人邮件地址")
	private String bccAddress;

	@ApiModelProperty(value = "发送时间", hidden = true)
	private LocalDateTime sendDate;

	@ApiModelProperty("发送开始时间")
	private LocalDateTime beginSendDate;

	@ApiModelProperty("发送截止时间")
	private LocalDateTime endSendDate;

	@ApiModelProperty("邮件标题")
	private String subject;

	@ApiModelProperty("邮件内容")
	private String text;

	public String getAppName() {
		return ConfigEnvironment.getAppName();
	}

	public void setEmailRecordReqVO(SimpleMailMessage mailMessage) {
		this.fromAddress = mailMessage.getFrom();
		this.replyToAddress = mailMessage.getReplyTo();
		this.toAddress = StringUtils.join(mailMessage.getTo());
		this.ccAddress = StringUtils.join(mailMessage.getCc());
		this.bccAddress = StringUtils.join(mailMessage.getBcc());
		this.sendDate = LocalDateTime.now();
		this.subject = mailMessage.getSubject();
		this.text = mailMessage.getText();
	}

}
